package com.shop2cn.iapi.agentproducts.testcase;

import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.BatchAutoImportProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.shop2cn.iapi.agentproducts.service.BatchAutoImportProductCall;
import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymatou.iapi.godmch.parameter.setConditionMarkupConfigBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
/**
*选货中心批量自动导入商品Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BatchAutoImportProduct{
	private static BatchAutoImportProductBean batchautoimportproductBean;
	private static BatchAutoImportProductCall batchautoimportproductCall;
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("选货中心批量自动导入商品Test");
	}

	@Before
	public void caseUp() {
		batchautoimportproductBean=new BatchAutoImportProductBean();
		batchautoimportproductCall=new BatchAutoImportProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(batchautoimportproductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BatchAutoImportProduct_001() {
		Logger.start(true,"符合自动加价规则，进行快速导入");
		try {
			Integer mchId = GodmchManageCallService.CreateGodMch();
            Integer agenttype=GodmchManageCallService.getAgentType(mchId, 1);
            Integer agent_mchId = GodmchManageCallService.getAgentMchId(mchId, agenttype);
            
            AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId, "", true);
            addAgentProductBean.setCategoryId(1001);
            setConditionMarkupConfigBean setConditionMarkupConfigBean = GodmchManageCallService.initDefSetConditionMarkupConfig(agent_mchId, mchId, 1, addAgentProductBean, 2);
            setConditionMarkupConfigBean.setRefreshProduct(true);
            setConditionMarkupConfigBean.setOnSaleType(2);
            GodmchManageCallService.SetConditionMarkupConfigCall(setConditionMarkupConfigBean);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            Thread.sleep(3000);
            batchautoimportproductBean.setUserId(agent_mchId);
            batchautoimportproductBean.setParentProductIds(Arrays.asList(productId));
			batchautoimportproductCall.setData(batchautoimportproductBean);
			batchautoimportproductCall.callService();			
			Logger.verifyEquals("200", batchautoimportproductCall.getString("code"), "验证code");
			Thread.sleep(3000);
			List<ProductListDto> getProductLists = AddAgentProductCallService.GetProductLists(agent_mchId);
			Logger.verifyEquals(1, getProductLists.size(), "已经自动添加并且查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BatchAutoImportProduct_002() {
		Logger.start(true,"根据分类id列表，进行快速导入");
		try {
			Integer mchId = GodmchManageCallService.CreateGodMch();
            Integer agenttype=GodmchManageCallService.getAgentType(mchId, 1);
            Integer agent_mchId = GodmchManageCallService.getAgentMchId(mchId, agenttype);
            
            AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId, "", true);
            addAgentProductBean.setCategoryId(1001);
            setConditionMarkupConfigBean setConditionMarkupConfigBean = GodmchManageCallService.initDefSetConditionMarkupConfig(agent_mchId, mchId, 1, addAgentProductBean, 2);
            setConditionMarkupConfigBean.setRefreshProduct(true);
            setConditionMarkupConfigBean.setOnSaleType(2);
            GodmchManageCallService.SetConditionMarkupConfigCall(setConditionMarkupConfigBean);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            
            Thread.sleep(3000);
            batchautoimportproductBean.setUserId(agent_mchId);
            batchautoimportproductBean.setCategoryIdLiist(Arrays.asList(1001));
			batchautoimportproductCall.setData(batchautoimportproductBean);
			batchautoimportproductCall.callService();			
			Logger.verifyEquals("200", batchautoimportproductCall.getString("code"), "验证code");
			
			Thread.sleep(3000);
			List<ProductListDto> getProductLists = AddAgentProductCallService.GetProductLists(agent_mchId);
			Logger.verifyEquals(1, getProductLists.size(), "已经自动添加并且查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BatchAutoImportProduct_003() {
		Logger.start(true,"根据品跑id列表，进行快速导入");
		try {
			Integer mchId = GodmchManageCallService.CreateGodMch();
            Integer agenttype=GodmchManageCallService.getAgentType(mchId, 1);
            Integer agent_mchId = GodmchManageCallService.getAgentMchId(mchId, agenttype);
            
            AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId, "", true);
            addAgentProductBean.setCategoryId(1001);
            setConditionMarkupConfigBean setConditionMarkupConfigBean = GodmchManageCallService.initDefSetConditionMarkupConfig(agent_mchId, mchId, 1, addAgentProductBean, 2);
            setConditionMarkupConfigBean.setRefreshProduct(true);
            setConditionMarkupConfigBean.setOnSaleType(2);
            GodmchManageCallService.SetConditionMarkupConfigCall(setConditionMarkupConfigBean);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            
            Thread.sleep(3000);
            batchautoimportproductBean.setUserId(agent_mchId);
            batchautoimportproductBean.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			batchautoimportproductCall.setData(batchautoimportproductBean);
			batchautoimportproductCall.callService();			
			Logger.verifyEquals("200", batchautoimportproductCall.getString("code"), "验证code");
			
			Thread.sleep(3000);
			List<ProductListDto> getProductLists = AddAgentProductCallService.GetProductLists(agent_mchId);
			Logger.verifyEquals(1, getProductLists.size(), "已经自动添加并且查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}